package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.MallService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 搜索页controller
 */
@Controller
public class SearchController {

    @Autowired
    MallService mallService;
    /**
     * 跳转至搜索页,自动将页面提交过来的所有请求查询封装成指定的对象
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request) {
        //将查询条件封装进去
        searchParam.set_queryString(request.getQueryString());
        //1、根据页面传递的查询参数去es中检索商品
        SearchResult result =  mallService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }

}
